import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueRouter from 'vue-router'
import router from './router';
import store from './store';



Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(VueRouter);
//钩子函数，访问路由前调用

router.beforeEach((to, from, next) => {
  //路由需要认证
  if (to.meta.requireAuth) {
    //判断store里是否有token
    if (store.state.id!='') {
      next()
    } else {
      next({
        path: '/',
        query: { redirect: to.fullPath }
      })
    }
  } else {
    next()
  }
});
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

